package main

import (
	"fmt"
	"errors"
)

const (
	a = 10
	b = 300
	c = 500
)

const (
	d = iota
	e = iota
	f = iota
	g
)

func main() {
	test3()
	test4()
	testif()
	testGoto()
	testFor()
	testMap()
	fmt.Println(max(11,22))
	a,b:=sum(11,22);
	fmt.Println(a,b)


}

func test3() {
	fmt.Println("test3")
	err := errors.New("this is a error!")
	fmt.Println(err)
	fmt.Println(a)
	fmt.Println(b)
	fmt.Println(c)
	fmt.Println(d)
	fmt.Println(e)
	fmt.Println(f)
	fmt.Println(g)

}

var array = [10] byte{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'}
func test4() {
	slice1 := array[:]
	fmt.Println(slice1);
	slice1 = array[:5]
	fmt.Println(slice1);
	slice1 = array[2:5]
	fmt.Println(slice1);
	slice1 = array[2:]
	fmt.Println(slice1);
	fmt.Println(cap(slice1));
}

func testif() {
	const max = 18
	if age := getAge(); age > max {
		fmt.Println("old boy")
	}else {
		fmt.Println("图样图森破")
	}
}

func getAge() int {
	return 10
}

func testGoto()  {
	i:=0
Here:
	fmt.Println(i)
	i++
	if i <10{
		goto Here
	}
}

func testFor()  {
	num:=0
	for ;num<10 ;  {
		fmt.Printf("num: %d \n" , num)
		num++
	}
}

func testMap()  {
//	var map1 map[string]int
	map1 := make(map[string]int)
	map1["aa"] = 1
	map1["bb"] = 2
	map1["cc"] = 3
	fmt.Println(map1)

	for k,v := range map1  {
		fmt.Printf("map key %s : map value %d \n"  ,k,v)
	}
}

func max(a,b int) int {
	if a>b{
		return a
	}else {
		return b
	}
}

func sum(x,y int)(a,b int)  {
	return x+y,x*y
}


